1
|
|
|
import { EditorState } from 'prosemirror-state'; |
2
|
|
|
import { EditorView } from 'prosemirror-view'; |
3
|
|
|
import { Node } from 'prosemirror-model'; |
4
|
|
|
|
5
|
|
|
import schema from './schema'; |
6
|
|
|
import getKeymapPlugin from './plugins/Keymap/keymap'; |
7
|
|
|
import initializePublicAPI from './initializePublicAPI'; |
8
|
|
|
import MenuInitializer from './plugins/Menu/MenuInitializer'; |
9
|
|
|
import getNodeViews from './nodeviews/index'; |
10
|
|
|
|
11
|
|
|
initializePublicAPI(); |
12
|
|
|
|
13
|
|
|
const mi = new MenuInitializer(schema); |
14
|
|
|
|
15
|
|
|
window.Prosemirror = window.Prosemirror || {}; |
16
|
|
|
|
17
|
|
|
window.Prosemirror.enableProsemirror = function enableProsemirror() { |
18
|
|
|
// PLUGIN ORDER IS IMPORTANT! |
19
|
|
|
const plugins = [ |
20
|
|
|
mi.getMenuPlugin(), |
21
|
|
|
getKeymapPlugin(schema), |
|
|
|
|
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
const json = jQuery('#dw__editform').find('[name=prosemirror_json]').get(0); |
25
|
|
|
const view = new EditorView(document.querySelector('#prosemirror__editor'), { |
26
|
|
|
state: EditorState.create({ |
27
|
|
|
doc: Node.fromJSON(schema, JSON.parse(json.value)), |
28
|
|
|
schema, |
29
|
|
|
plugins, |
30
|
|
|
}), |
31
|
|
|
dispatchTransaction(tr) { |
32
|
|
|
console.log('run'); |
|
|
|
|
33
|
|
|
|
34
|
|
|
view.updateState(view.state.apply(tr)); |
35
|
|
|
|
36
|
|
|
const spaces = 4; |
37
|
|
|
json.value = JSON.stringify(view.state.doc.toJSON(), null, spaces); // FIXME: no need to pretty print this! |
38
|
|
|
}, |
39
|
|
|
nodeViews: getNodeViews(), |
40
|
|
|
}); |
41
|
|
|
window.view = view; |
42
|
|
|
jQuery(window).on('scroll.prosemirror_menu', () => { |
43
|
|
|
const $container = jQuery('#prosemirror__editor'); |
44
|
|
|
const $menuBar = $container.find('.menubar'); |
45
|
|
|
const docViewTop = jQuery(window).scrollTop(); |
46
|
|
|
const containerTop = $container.offset().top; |
47
|
|
|
|
48
|
|
|
if (docViewTop > containerTop) { |
49
|
|
|
$menuBar.css('position', 'fixed'); |
50
|
|
|
} else { |
51
|
|
|
$menuBar.css('position', ''); |
52
|
|
|
} |
53
|
|
|
}); |
54
|
|
|
}; |
55
|
|
|
|
56
|
|
|
window.Prosemirror.destroyProsemirror = function destroyProsemirror() { |
57
|
|
|
if (window.view && typeof window.view.destroy === 'function') { |
58
|
|
|
window.view.destroy(); |
59
|
|
|
} |
60
|
|
|
jQuery(window).off('scroll.prosemirror_menu'); |
61
|
|
|
}; |
62
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.